package com.kuaixueit.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaixueit.crm.mapper.CDeptMapper;
import com.kuaixueit.crm.pojo.CDept;
import com.kuaixueit.crm.service.DeptService;

@Service
public class DeptServiceImpl implements DeptService {
  
  
  @Autowired
  private CDeptMapper deptMapper;

  @Override
  public CDept getDeptById(Integer id) {
    return deptMapper.selectByPrimaryKey(id);
  }

  @Override
  public PageInfo getPageList(Integer pageNum, Integer pageSize ,String deptName) {
    //使用分页插件
    PageHelper.startPage(pageNum, pageSize);
    List<CDept> list = deptMapper.getList(deptName);
    PageInfo info = new PageInfo(list);
    return info;
  }
  //添加用户信息
  public Integer add(CDept dept) {
    dept.setId(null);
    dept.setCreateTime(new Date());
    dept.setUpdateTime(new Date());
    return deptMapper.insert(dept);
  }

  //修改用户信息
  public Integer updateDept(CDept dept) {
    //获取部门id
    Integer id = dept.getId();
    if(id == null){
      return 0 ;
    }
    dept.setUpdateTime(new Date());
    int i = deptMapper.updateByPrimaryKeySelective(dept);
    return i;
  }

  //删除部门信息
  public Integer delete(Integer id) {
     //调用方法删除
    return deptMapper.deleteByPrimaryKey(id);
  }

}
